import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:flutter_smart_dialog/flutter_smart_dialog.dart';
import 'package:get/get.dart';
import 'package:pornhub_app/assets/styles.dart';
import 'package:pornhub_app/components/easy_button.dart';
import 'package:pornhub_app/model/play/video_detail_model.dart';
import 'package:pornhub_app/utils/color.dart';
import 'package:pornhub_app/utils/enum.dart';
import 'package:pornhub_app/utils/extension.dart';
import 'package:pornhub_app/views/player/controllers/video_play_controller.dart';

import '../../../routes/routes.dart';

class AvPermissionUI extends StatelessWidget {
  final VideoDetail model;
  final VoidCallback? payAction;
  const AvPermissionUI({super.key, required this.model, this.payAction});
  _buildWXTS() {
    return Text("温馨提示",
            style: kTextStyle(COLOR.hexColor("#333"),
                fontsize: 16.w, weight: FontWeight.w600))
        .marginTop(15.w);
  }

  _buildLine() {
    return Container(height: 1.0, color: COLOR.hexColor("#F0F0F0"))
        .marginTop(18.w);
  }

  _buildTitle() {
    final isPay = model.reasonType! == VideoReasonTypeValueEnum.NeedPay;
    final isLuoli = model.reasonType! == VideoReasonTypeValueEnum.Luoli;
    final txt = isLuoli ? '本视频需要开通萝莉岛会员' : '本视频需要开通浅网会员';
    return isPay
        ? RichText(
            text: TextSpan(children: [
            TextSpan(
                text: '${model.price!}金币',
                style: TextStyle(
                    fontSize: 16.w,
                    color: COLOR.hexColor("#F40302"),
                    fontWeight: FontWeight.w500)),
            TextSpan(
                text: '购买完整视频',
                style: TextStyle(
                    fontSize: 16.w,
                    color: COLOR.hexColor('#333'),
                    fontWeight: FontWeight.w500)),
          ])).marginTop(20.w)
        : Text(txt,
                style: kTextStyle(COLOR.hexColor("#333"),
                    fontsize: 16.w, weight: FontWeight.w600))
            .marginTop(20.w);
  }

  _buildDesc() {
    final isPay = model.reasonType! == VideoReasonTypeValueEnum.NeedPay;
    return Text(
      isPay ? '购买之后即可永久观看' : "升级至尊会员享受全站无限观影特权",
      style: kTextStyle(COLOR.hexColor("#333"), fontsize: 14.w),
    ).marginTop(12.w);
  }

  _dismiss() {
    SmartDialog.dismiss(tag: VideoPlayController.permissionDialogTag);
  }

  _buildBtns() {
    final isPay = model.reasonType! == VideoReasonTypeValueEnum.NeedPay;
    return SizedBox(
      width: 244.w,
      child: Row(
        mainAxisAlignment: MainAxisAlignment.spaceBetween,
        crossAxisAlignment: CrossAxisAlignment.center,
        children: [
          EasyButton(
            "稍后再说",
            backgroundColor: COLOR.hexColor("#E5E5E5"),
            borderRadius: BorderRadius.circular(18.w),
            height: 36.w,
            width: 112.w,
            textStyle: kTextStyle(COLOR.hexColor("#666"), fontsize: 16.w),
            onTap: () {
              _dismiss();
            },
          ),
          EasyButton(
            isPay ? "立即支付" : "立即开通",
            borderRadius: BorderRadius.circular(18.w),
            backgroundGradient: LinearGradient(
                begin: Alignment.centerLeft,
                end: Alignment.centerRight,
                colors: [
                  COLOR.hexColor('#F78248'),
                  COLOR.hexColor('#F52C0F'),
                  COLOR.hexColor('#F5019A')
                ]),
            height: 36.w,
            width: 112.w,
            textStyle: kTextStyle(COLOR.hexColor("#fff"), fontsize: 16.w),
            onTap: () {
              if (isPay) {
                //支付
                if (payAction != null) {
                  payAction!();
                }
                return;
              }
              _dismiss();
              Get.toNamed(Routes.vip);
            },
          )
        ],
      ),
    ).marginTop(25.w);
  }

  @override
  Widget build(BuildContext context) {
    return Container(
      height: 212.w,
      width: 300.w,
      decoration: BoxDecoration(
          color: Colors.white, borderRadius: BorderRadius.circular(12.w)),
      child: Column(
        crossAxisAlignment: CrossAxisAlignment.center,
        children: [
          _buildWXTS(),
          _buildLine(),
          _buildTitle(),
          _buildDesc(),
          _buildBtns(),
        ],
      ),
    );
  }
}
